<?php

/**
 * Description of LiberyAccountValidator
 *
 * @author Ho Huu Tai <hohuutai.uns@gmail.com>
 */
class LiberyAccountValidator extends CValidator
{
    public function validateAttribute($object, $attribute)
    {
        $value = $object->$attribute;
        $libertyAPI = new LibertAPIWrapper();
        if(!$libertyAPI->checkLiberyAccountExist($value))
        {
            $message=$this->message!==null?$this->message:Yii::t('lode','{attribute} "{value}" không tồn tại');
            $this->addError($object,$attribute,$message,array('{value}'=>$value));
            return;
        }
        
        $isUsed = User::model()->exists('lr_acc=:lr_acc', array(':lr_acc'=>$value));
        if($isUsed)
        {
            $message=$this->message!==null?$this->message:Yii::t('lode','{attribute} "{value}" đã được sử dụng');
            $this->addError($object,$attribute,$message,array('{value}'=>$value));
        }
    }
    
    public function clientValidateAttribute($object, $attribute)
    {
        
    }
}

?>
